Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

330
Vistas
JavaScript Discord Embed is not reading certain Embed.set commands. (Discord meme bot) [[Solved]]

I'm trying to make a discord meme bot (in this case, cute animal pictures bot). The code is this; code screenshot

But when I use the command in discord, the reply only shows the description, not the color or image.

discord screenshot

What am I doing wrong?

here's the code of the command file for copy paste;

const { MessageEmbed } = require('discord.js');
const randomPuppy = require('random-puppy');

module.exports = {
    name: 'cute',
    description: 'Embeds pictures pulled from listed subreddits',
    execute(message, args, Discord){
        let reddit = [
            "aww",
            "puppies",
            "toebeans"
        ]

        let subreddit = reddit[Math.floor(Math.random()*reddit.length -1)];

        const cuteEmbed = new MessageEmbed()
        .setDescription("Some cute animals to blow away your anxieties!");

        randomPuppy(subreddit).then(url => {
            console.log(url);
            const cuteurl = url;
            
            cuteEmbed.setColor('#91B2C7');
            cuteEmbed.setImage('${cuteurl}');
            });

            message.channel.send(cuteEmbed);
        }
    }

please help :'(

Edit: BACK TICKS. GODDAMN BACK TICKS. I'm using a new code so idk if using back ticks would've fixed it, but that's one mistake in the code; I didn't use backticks for interpolation.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The method randomPuppy() is asynchronous. Meaning that you need to wait for the promise to send the embed message. In your current code, you send the embed without waiting for the request to complete.

You have to change your code from:

randomPuppy(subreddit).then(url => {
  cuteEmbed.setColor('#91B2C7');
  cuteEmbed.setImage('${url}');
});

message.channel.send(cuteEmbed);

To:

randomPuppy(subreddit).then(url => {
  cuteEmbed.setColor('#91B2C7');
  cuteEmbed.setImage('${url}');
  message.channel.send(cuteEmbed); //Send the embed once the request is completed.
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

    randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url;
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage('${cuteurl}');
        });

        message.channel.send(cuteEmbed);
    }

You are trying to send the embed even the request is not finished, all you need to do is to put the message.channel.send() inside of .then

    randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url;
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage('${cuteurl}');
        message.channel.send(cuteEmbed);
        });
    }

And I noticed something that you missed type one of the keypress you should type backquote instead of quote, so after editing your code. You just need to edit the quote to backquote:

    randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url;
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage('${cuteurl}'); //This is the part you need to change it
        message.channel.send(cuteEmbed);
        });
    }

To this:

   randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url; //image should call this after changing it
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage(`${cuteurl}`); //To this, to call your cuteurl
        message.channel.send(cuteEmbed);
        });
    }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda